/* Copyright (c) 2016-2020 Enfry Ltd. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of Enfry. 
 * You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with Enfry.
 */
package com.enfry.common.util.array;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import com.enfry.common.util.annotation.AnAlias;

/**
 * 
 * <请简单说明此类用途>
 * 
 * @Title com.enfry.util.Listx
 * @author Penghu
 * @date 2018年1月10日
 */
@AnAlias("Listx")
public class Listx extends Collectionx {
	// Query Operations 查询操作

	public static int size(List<?> list) {
		return (list == null) ? 0 : list.size();
	}

	public static boolean isEmpty(List<?> list) {
		return (list == null) ? true : list.isEmpty();
	}

	public static boolean contains(List<?> list, Object o) {
		return (list == null) ? false : list.contains(o);
	}

	public static <E> Iterator<E> iterator(List<E> list) {
		return list.iterator();
	}

	public static Object[] toArray(List<?> list) {
		return list.toArray();
	}

	public static <T> T[] toArray(List<T> list, T[] a) {
		return list.toArray(a);
	}

	// Modification Operations 修改操作

	public static <E> boolean add(List<E> list, E e) {
		return (list == null) ? false : list.add(e);
	}

	public static boolean remove(List<?> list, Object o) {
		return (list == null) ? false : list.remove(o);
	}

	// Bulk Modification Operations 批量修改操作

	public static boolean containsAll(List<?> list, Collection<?> c) {
		return (list == null) ? false : list.containsAll(c);
	}

	public static <E> boolean addAll(List<E> list, Collection<? extends E> c) {
		return (list == null) ? false : list.addAll(c);
	}

	public static <E> boolean addAll(List<E> list, int index, Collection<? extends E> c) {
		return (list == null) ? false : list.addAll(index, c);
	}

	public static boolean removeAll(List<?> list, Collection<?> c) {
		return (list == null) ? false : list.removeAll(c);
	}

	public static boolean retainAll(List<?> list, Collection<?> c) {
		return (list == null) ? false : list.retainAll(c);
	}

	public static void clear(List<?> list) {
		if (list == null)
			return;

		list.clear();
	}

	// Comparison and hashing

	public static boolean equals(List<?> list, Object o) {
		return list.equals(o);
	}

	public static int hashCode(List<?> list) {
		return list.hashCode();
	}

	// Positional Access Operations

	public static <E> E get(List<E> list, int index) {
		return list.get(index);
	}

	public static <E> E set(List<E> list, int index, E element) {
		return list.set(index, element);
	}

	public static <E> void add(List<E> list, int index, E element) {
		list.add(index, element);
	}

	public static <E> E remove(List<E> list, int index) {
		return list.remove(index);
	}

	public static int indexOf(List<?> list, Object o) {
		return list.indexOf(o);
	}

	public static int lastIndexOf(List<?> list, Object o) {
		return list.lastIndexOf(o);
	}

	public static <E> ListIterator<E> listIterator(List<E> list) {
		return list.listIterator();
	}

	public static <E> ListIterator<E> listIterator(List<E> list, int index) {
		return list.listIterator(index);
	}

	public static <E> List<E> subList(List<E> list, int fromIndex, int toIndex) {
		return list.subList(fromIndex, toIndex);
	}

}
